package com.ionehe.group.common.file.autoconfigure;

import com.ionehe.group.common.file.FileServer;
import com.ionehe.group.common.file.configure.FileServerConfiguration;
import com.ionehe.group.common.file.minio.factory.FileFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Copyright (c) 2021 ionehe.com
 * Date: 2021/4/26
 * Time: 9:40 上午
 *
 * @author 2021年 <a href="mailto:a@ionehe.com">秀</a>
 * 【自动装配】
 */

@Configuration
@ComponentScan({"com.ionehe.group.common.file"})
@EnableConfigurationProperties({FileServerConfiguration.class})
public class FileAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "file", name = {"vendor"}, havingValue = "minio")
    public FileServer minioFileServer(FileServerConfiguration configuration) {
        return new FileFactory(configuration).create();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "file", name = {"vendor"}, havingValue = "oss")
    public FileServer ossFileServer(FileServerConfiguration configuration) {
        return new com.ionehe.group.common.file.oss.factory.FileFactory(configuration).create();
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "file", name = {"vendor"}, havingValue = "cos")
    public FileServer cosFileServer(FileServerConfiguration configuration) {
        return new com.ionehe.group.common.file.cos.factory.FileFactory(configuration).create();
    }
}
